package com.zzj.web.utils;

import com.zzj.bill.domain.BillShop;
import com.zzj.bill.domain.BillUserShop;
import com.zzj.bill.service.IShopService;
import com.zzj.bill.service.IUserShopService;
import com.zzj.common.core.domain.model.LoginUser;
import com.zzj.common.utils.SecurityUtils;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author zengZhiJun
 * @create 2022/1/25 10:27
 */
public abstract class BillUtils {


    public static Pair<LoginUser,  List<BillShop>> getLoginUserInfo() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        IUserShopService userShopService = SpringContextHolder.getBean(IUserShopService.class);
        IShopService shopService = SpringContextHolder.getBean(IShopService.class);
        List<BillUserShop> billUserShops = userShopService.selectUserShopByUserId(loginUser.getUserId().intValue());
        List<BillShop> billShopList = Lists.newArrayList();
        if(!CollectionUtils.isEmpty(billUserShops)){
            billShopList = shopService.beathSelectByShopIds(billUserShops.stream().map(BillUserShop::getShopId).collect(Collectors.toList()));
        }
        return Pair.of(loginUser, billShopList);
    }
}
